#!/bin/bash
#1 ip 2 netmask 3 gateway 4.dns 5.dhcp static 6.eth0
if [ $# -lt 5 ];then
	echo "参数不够";
	exit;
fi
data_time=`date "+%Y-%m-%d_%H:%M:%S.%N"`
sudo cp /etc/network/interfaces /etc/network/"interfaces_back_$data_time"
#sudo su

echo 'auto lo' > /etc/network/interfaces
echo "auto $6" >> /etc/network/interfaces
echo "iface lo inet loopback" >> /etc/network/interfaces
echo "allow-hotplug $6" >> /etc/network/interfaces

echo "iface $6 inet $5"  >> /etc/network/interfaces
echo "address $1" >> /etc/network/interfaces
echo "netmask $2" >> /etc/network/interfaces
echo "gateway $3" >> /etc/network/interfaces
echo "DNS=$4" >> /etc/systemd/resolved.conf

#/etc/init.d/networking restart

reboot
